/*
 *  Copyright 2024 Collate.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

@import (reference) '../../../../../../styles/variables.less';

.query-builder-card {
  background-color: @grey-6;

  .ant-alert-info {
    background-color: @blue-8;
    border-color: @blue-7;

    .ant-alert-icon {
      color: @blue-7;
    }
  }
}

.query-builder-form-field
  .query-builder-card.jsonlogic
  .query-builder-container {
  .group-or-rule-container.group-container {
    & > .group.group-or-rule {
      & > .group--header {
        order: 0;

        .action.action--ADD-RULE {
          position: absolute !important;
          margin-top: 0;
          right: 0;
          top: -56px; // updating this as size of button is increased
          display: block;
        }
      }
    }
  }
}

.query-filter-label {
  text-transform: capitalize;
}

.query-builder-form-field {
  .ant-select-disabled.ant-select:not(.ant-select-customize-input)
    .ant-select-selector {
    color: @black;
    background-color: @background-color;
  }

  .hide--line.one--child {
    margin-top: 0;
    padding-top: 16px;
  }

  .group.rule_group {
    border: none !important;
    padding: 0;

    .group--children {
      padding-top: 0;
      padding-bottom: 0;
      margin: 0;
    }
  }

  .group--field {
    width: 180px;

    .ant-select {
      width: 100% !important;
    }

    label {
      font-weight: normal;
      margin-bottom: 6px;
    }
  }

  .query-builder-container {
    .group-or-rule-container.rule-container {
      padding: 0px;

      .rule.group-or-rule {
        .rule--header {
          .ant-btn-group {
            margin: 0 !important;
            align-self: flex-start;
          }
        }
      }
    }

    .group-or-rule-container.group-container {
      padding: 0px;

      .group.rule_group {
        .group--field {
          margin: 0px;
          flex: 0 1 25%;

          .ant-select {
            min-width: 100% !important; // override the inline min-width style of the select provided by antd
          }
        }
      }

      & > .group.group-or-rule {
        display: flex;
        flex-direction: column;

        & > .group--header {
          order: 9999;

          .group--actions.group--actions--tr {
            justify-content: flex-start;
            margin: 0px;
          }

          .action.action--ADD-GROUP {
            display: none;
          }

          .rule-container .ant-btn-group {
            visibility: visible;
          }

          .action.action--ADD-RULE {
            position: static !important;
            margin-top: 8px;
          }
        }

        .rule--body--wrapper {
          .rule--body {
            margin: 0px;
            display: flex;
            gap: 16px;

            .group--field,
            .rule--field,
            .rule--operator,
            .rule--value,
            .widget--widget {
              margin: 0px;
              flex: 1;

              .ant-col {
                padding: 0px !important; // remove padding from ant-col inline styling by antd
              }
            }

            .rule--operator,
            .rule--value .rule--widget {
              width: 100%;

              .ant-select {
                min-width: 100% !important; // override the inline min-width style of the select provided by antd
              }
            }
          }
        }
      }

      & > .group.group-or-rule.rule_group {
        flex-direction: row;
        align-items: center;
      }
    }

    .group--children {
      padding: 0px;
      margin: 0px;

      .group-or-rule-container.group-container,
      .group-or-rule-container.rule-container {
        .group.group-or-rule,
        .rule.group-or-rule {
          background: inherit;
          padding: 0px;
          border: none;

          .group--header {
            .group--conjunctions {
              display: none;
            }
          }

          &:not(:first-child) {
            padding: 16px 8px;
          }
        }
      }

      .rule-container .ant-btn-group {
        visibility: visible;
      }
    }
  }

  .rule {
    align-items: center;
  }
}

.query-builder-card.elasticsearch {
  .rule-container:first-child .action--DELETE {
    display: none;
  }
}

.json-logic-field-select {
  .ant-select-item-group {
    padding-left: 8px;
    position: relative;
    color: @text-color;
    font-size: 14px;
    background-color: @grey-6;
  }

  /* Add vertical line for children */
  .ant-select-item-option-grouped {
    position: relative;
    padding-left: 32px;
    /* Indentation for child items */
  }

  /* Add vertical line before each child */
  .ant-select-item-option-grouped::before {
    content: '';
    position: absolute;
    left: 16px;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: @border-color;
  }

  /* Adjust line height for last child */
  .ant-select-item-option-grouped:last-child::before {
    height: 16px;
    bottom: auto;
  }

  /* Add horizontal connector for each child */
  .ant-select-item-option-grouped::after {
    content: '';
    position: absolute;
    left: 16px;
    top: 16px;
    width: 10px;
    height: 1px;
    background-color: @border-color;
  }
}

.query-builder-card.jsonlogic {
  .query-builder-container
    .group-or-rule-container.group-container
    > .group.group-or-rule
    > .group--header
    .group--conjunctions {
    top: -75px;
  }

  .rule_group--children .rule--field {
    display: none;
  }
}
